package com.atguigu.gmall.pms.config;

import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author 刘嘉乐
 * @Date 2022/1/9 12:47
 * @Version 1.0
 */
@Configuration
@Slf4j
public class RabbitConfig {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @PostConstruct
    public void init(){
        this.rabbitTemplate.setConfirmCallback((correlationData, ack,cause)->{
            if (!ack){
             log.error("消息没有到达交换机{}",cause);
            }
        });
        this.rabbitTemplate.setReturnCallback(( message,  replyCode, replyText,  exchange, routingKey)->{
            log.error("消息没有到达队列，交换机{}，路由建{}，消息内容{}，状态码{}，状态文本{}"
                    ,exchange,routingKey,message,replyCode,replyText);
        });
    }

}
